/**
 ******************************************************************************
 * @file           : main.c
 * @brief          : Timer Interrupt Example (STM32H7xx)
 ******************************************************************************
 */

#include "stm32h7xx.h"
#include "./BSP/TIMER/bsp_timer.h"
#include "./BSP/GPIO/bsp_gpio.h"
#include "./BSP/USART/bsp_usart.h"
#include <stdio.h>

volatile uint32_t g_timer_count = 0;

void timer_callback(void)
{
    g_timer_count++;

    if (g_timer_count >= 1000)
    {
        g_timer_count = 0;
        gpio_toggle(GPIOA, GPIO_PIN_5);
        printf("LED toggled\r\n");
    }
}

int main(void)
{
    HAL_Init();
    SystemClock_Config();

    usart_init(115200);
    gpio_init(GPIOA, GPIO_PIN_5, GPIO_MODE_OUTPUT_PP, GPIO_SPEED_FREQ_LOW);

    printf("Timer Interrupt Example\r\n");

    timer_init(1000);
    timer_set_callback(timer_callback);
    timer_start();

    printf("Timer started\r\n");

    while (1)
    {
        HAL_Delay(100);
    }
}

void SystemClock_Config(void)
{
    /* 系统时钟配置（由STM32CubeMX生成） */
}
